﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using pos.excption;
using System.Collections;
using Spring.Data.NHibernate.Support;
using Spring.Data.NHibernate;
using NHibernate;
using NHibernate.Criterion;

namespace pos.entity
{
    class PaySettle : IHibernateCallback
    {

         private Hashtable m_list;
         private double m_salemoney;
         private double m_paymoney;
         public long orderno { get; set; }  
         public PaySettle(Hashtable list,double salemoney ,double paymoney)
         {
             m_list = list;
             m_salemoney = salemoney;
             m_paymoney = paymoney;
         }
         public object DoInHibernate(ISession session)
        {

            long lseq = (DateTime.Now-new DateTime(2010,1,1)).Ticks/10000000;
           
            t_saleorder order = new t_saleorder();

            order.saleAmount = 0;
            order.saleMoney = 0;
            order.payMoney = 0;
            order.changeMoney = 0;
            order.seqID = 1;

          
            foreach (System.Collections.DictionaryEntry item in m_list)
            {
                t_sale p = (t_sale)item.Value;
             //   sequence s = new sequence(t_sale.SEQN0);
            //    p.seqID = s.getNumberSequence();
            //    if (lseq < 0)
              //      lseq = p.seqID;
              
              //  s.UpdateSequence();
                if (order.saleAmount == 0)
                {
                    order.saleTime = DateTime.Now;
                    order.userID = p.userID;
                    order.cashboxNO = p.cashboxNO;
                    order.memberSeqID = p.memberSeqID;
                    order.add();
                }

                order.saleAmount++;
                order.saleMoney+= p.saleAmount * p.salePrice;
                p.moneySeqID = order.seqID;
                p.add();
              
            }
            order.payMoney = this.m_paymoney;
            order.changeMoney = this.m_paymoney - this.m_salemoney;
            order.update();

            orderno = order.seqID;
          
        

            return true;
        }


    }
}
